package org.ainlolcat.ainscience.statistics.handlers.hitran;

import org.ainlolcat.ainscience.tools;

/**
 * @author ainlolcat
 *         Date: 5/1/13
 */
public strictfp class SpectrLine{
    double multipleCoeff = 1E20;
	double ia = 0.0;
	double A  = 0.0;
	double N1 = 0.0;
	double J1 = 0.0;
	double N2 = 0.0;
	double J2 = 0.0;
	String mode1 = "";
	String mode2 = "";
	double I = 0.0;
	boolean Serror = true;
	boolean isfill = false;
	double nJA = 0.0;
	double E0 = 0.0;
	double E2 = 0.0;
	double kex = 0.0;

	private double getDouble(String s){
        return tools.parseDouble(s);
    }

	private void clear(){
		isfill = false;
		Serror = true;
    }

	public boolean fill(String[] temp){
		try{
            mode1 	= temp[4];
			mode2 	= temp[6];
			ia 	= getDouble(temp[0]);
			A 	= getDouble(temp[2]);
			E0 	= getDouble(temp[3]);
			N1 	= getDouble(temp[5]);
			J1 	= getDouble(temp[7]);
			I 	= 0;
			isfill = true;
			Serror = false;
			perform();
			return true;
        }
		catch(Exception e){
			Serror = true;
			System.out.println("Error: raw.fill: " + e.getLocalizedMessage());
			return false;
        }
    }

	private void perform(){
		if (mode1.equals("P") && mode2.equals("P")){ N2 = N1 - 1; 	J2 = J1 - 1;}
        if (mode1.equals("P") && mode2.equals("Q")){ N2 = N1 - 1; 	J2 = J1;    }

        if (mode1.equals("Q") && mode2.equals("P")){ N2 = N1;    	J2 = J1 + 1;}
        if (mode1.equals("Q") && mode2.equals("R")){ N2 = N1;    	J2 = J1 + 1;}
        if (mode1.equals("Q") && mode2.equals("Q")){ N2 = N1;    	J2 = J1;    }

        if (mode1.equals("R") && mode2.equals("R")){ N2 = N1 + 1;   J2 = J1 + 1;}
        if (mode1.equals("R") && mode2.equals("Q")){ N2 = N1 + 1;   J2 = J1;    }

        if (mode1.equals("O") && mode2.equals("P")){ N2 = N1 - 2;   J2 = J1 - 1;}
        if (mode1.equals("S") && mode2.equals("R")){ N2 = N1 + 2;   J2 = J1 + 1;}

		E2 = E0 + ia;
		nJA = (2 * J2 + 1) * A;
		kex = -(E2 * 1.986 * Math.pow(10, -23) / (1.380662 * Math.pow(10, -23)));
    }

    public double getCenter(){
        return 1/ia * 10000000;
    }

	public double getIntensity(double T){
		return multipleCoeff*nJA * Math.exp(kex/T);
    }
}
